package com.base.common.webservice.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.base.common.json.JsonUtil;
import com.base.common.webservice.ServiceConfigConstants;
import com.base.common.webservice.SYS86Service.SYS86Service;
import com.base.common.webservice.SYS86Service.SYS86ServiceSoap;
import com.base.common.webservice.entity.SYS86Service.SYS86ServiceArgs;
import com.base.common.webservice.entity.SYS86Service.UserRevGetFeeListBean;
import com.base.common.webservice.entity.SYS86Service.UserRevGetFeeListByResBean;
import com.base.common.webservice.entity.SYS86Service.UserRevGetOwnerInforBean;
import com.base.common.webservice.entity.SYS86Service.UserRevOwnerVerifyBean;
import com.base.common.webservice.enums.FeeType;
import com.base.common.webservice.factory.SYS86ServiceFactory;
import com.base.common.webservice.factory.WebServiceFactory;

/**
 * 
 * @author Kat Colin
 *
 */
public class SYS86ServiceUtil {

	private static String strStoken = ServiceConfigConstants.STRSTOKEN;

	/**
	 * 根据物业系统中业主或租户姓名检索业主或租户相关信息进行认证
	 * 
	 * @param CusName
	 *            客户姓名
	 * @param ProjectID
	 *            项目ID， 可为空，为空时表示所有项目
	 * @return
	 */
	public static List<UserRevGetOwnerInforBean> getUserRev_GetOwnerInfor(
			String CusName, String ProjectID) {

		// 配置参数

		SYS86ServiceArgs sys86ServiceArgs = new SYS86ServiceArgs();
		sys86ServiceArgs.setStrToken(strStoken);
		sys86ServiceArgs.setP0(ServiceConfigConstants.USERREV_GETOWNERINFOR);
		sys86ServiceArgs.setP1(CusName);
		sys86ServiceArgs.setP2(ProjectID);

		// xxxxUtil调用接口方法

		List<UserRevGetOwnerInforBean> ownerInforBeans = SYS86ServiceUtil
				.getSYS86Service(UserRevGetOwnerInforBean.class,
						sys86ServiceArgs);
		return ownerInforBeans;
	}

	/**
	 * 按客户获取该客户所有资源应缴费用
	 * 
	 * @param CusID
	 *            客户ID
	 * @param startTime
	 *            开始年月， 可为空
	 * @param endTime
	 *            结束年月，可为空
	 * @param ProjectID
	 *            项目ID
	 * @param feeType
	 *            查询费用范围，，可为空，为空则查询所有费用 {@linkplain FeeType}
	 * @return
	 */
	public static List<UserRevGetFeeListBean> getUserRev_GetFeeList(
			String CusID, String startTime, String endTime, String ProjectID,
			String feeType) {
		SYS86ServiceArgs sys86ServiceArgs = new SYS86ServiceArgs();
		sys86ServiceArgs.setStrToken(strStoken);
		sys86ServiceArgs.setP0(ServiceConfigConstants.USERREV_GETFEELIST);
		sys86ServiceArgs.setP1(CusID);
		sys86ServiceArgs.setP2(startTime);
		sys86ServiceArgs.setP3(endTime);
		sys86ServiceArgs.setP4(ProjectID);
		sys86ServiceArgs.setP5(feeType);

		// xxxxUtil调用接口方法

		List<UserRevGetFeeListBean> feeListBeans = SYS86ServiceUtil
				.getSYS86Service(UserRevGetFeeListBean.class, sys86ServiceArgs);
		return feeListBeans;
	}

	/**
	 * 按资源获取该资源所有应缴费用
	 * 
	 * @param ResID
	 *            资源ID
	 * @param startTime
	 *            开始年月，可为空
	 * @param endTime
	 *            结束年月，可为空
	 * @param ProjectID
	 *            项目ID
	 * @param feeType
	 *            查询费用范围 ，可为空，为空则查询所有费用{@linkplain FeeType}
	 * @return
	 */
	public static List<UserRevGetFeeListByResBean> getUserRev_GetFeeListByRes(
			String ResID, String startTime, String endTime, String ProjectID,
			String feeType) {
		SYS86ServiceArgs sys86ServiceArgs = new SYS86ServiceArgs();
		sys86ServiceArgs.setStrToken(strStoken);
		sys86ServiceArgs.setP0(ServiceConfigConstants.USERREV_GETFEELIST);
		sys86ServiceArgs.setP1(ResID);
		sys86ServiceArgs.setP2(startTime);
		sys86ServiceArgs.setP3(endTime);
		sys86ServiceArgs.setP4(ProjectID);
		sys86ServiceArgs.setP5(feeType);

		// xxxxUtil调用接口方法

		List<UserRevGetFeeListByResBean> feeListByResBeans = SYS86ServiceUtil
				.getSYS86Service(UserRevGetFeeListByResBean.class,
						sys86ServiceArgs);
		return feeListByResBeans;
	}

	/**
	 * 根据物业系统中业主、租户姓名和预留的手机号进行认证
	 * 
	 * @param CusName
	 *            客户名称，可为空
	 * @param MobileNo
	 *            客户手机号
	 * @param ProjectID
	 *            项目ID， 可为空，为空时表示所有项目
	 * @return
	 */
	public static List<UserRevOwnerVerifyBean> getUserRev_OwnerVerify(
			String CusName, String MobileNo, String ProjectID) {
		// 配置参数

		SYS86ServiceArgs sys86ServiceArgs = new SYS86ServiceArgs();
		sys86ServiceArgs.setStrToken(strStoken);
		sys86ServiceArgs.setP0(ServiceConfigConstants.USERREV_OWNERVERIFY);
		sys86ServiceArgs.setP1(CusName);
		sys86ServiceArgs.setP2(MobileNo);
		sys86ServiceArgs.setP3(ProjectID);

		// xxxxUtil调用接口方法

		List<UserRevOwnerVerifyBean> revOwnerVerifyBeans = SYS86ServiceUtil
				.getSYS86Service(UserRevOwnerVerifyBean.class, sys86ServiceArgs);
		return revOwnerVerifyBeans;
	}

	/**
	 * 访问接口获得返回数据
	 * 
	 * @param clazz
	 *            接收数据实体类类型
	 * @param sys86ServiceArgs
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> List<T> getSYS86Service(Class<?> clazz,
			SYS86ServiceArgs sys86ServiceArgs) {
		// 创建webservice工厂
		WebServiceFactory webServiceFactory = SYS86ServiceFactory.getInstance();

		// 获取service
		SYS86Service sys86Service = webServiceFactory.getSYS86Service();
		SYS86ServiceSoap sys86ServiceSoap = sys86Service.getSYS86ServiceSoap();

		// 访问webservice，获取数据
		List<Object> objs = (List<Object>) JsonUtil.string2Obejct(
				sys86ServiceSoap.getSYS86Service(
						sys86ServiceArgs.getStrToken(),
						sys86ServiceArgs.getP0(), sys86ServiceArgs.getP1(),
						sys86ServiceArgs.getP2(), sys86ServiceArgs.getP3(),
						sys86ServiceArgs.getP4(), sys86ServiceArgs.getP5(),
						sys86ServiceArgs.getP6(), sys86ServiceArgs.getP7()),
				Map.class).get(sys86ServiceArgs.getP0());
		Map<String, Object> map = (Map<String, Object>) objs.get(0);

		List<T> ts = new ArrayList<T>();
		for (Map<String, Object> object : (List<Map<String, Object>>) map
				.get("Syswin")) {
			T t = EasyUtils.mapToObject(clazz, object);
			ts.add(t);
		}
		return ts;
	}

}
